home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / bplus25a.zip / VTEST.C < prev   
Text File  |  1990-12-30  |  3KB  |  108 lines

  1. /*                     VTEST.C test program.                        */
  2. /*  This is a simple test program which creates two index files.    */
  3. /*  100 keys are added to each file, some keys are deleted and      */
  4. /*  then the keys are added back to the file.  The keys are listed  */
  5. /*  in ascending and decending order.                               */
  6.  
  7. #include "bplus.h"
  8. #include <stdio.h>
  9. #include <time.h>
  10. #include <conio.h>
  11.  
  12.  
  13. IX_DESC name1, name2;        /* index file variables */
  14.  
  15. /* function prototypes */
  16. void uplist (IX_DESC *);
  17. void downlist (IX_DESC *);
  18.  
  19.  
  20.  
  21. void uplist(name)            /* list keys in ascending order */
  22.   IX_DESC *name;
  23.   {
  24.     ENTRY ee;
  25.     if (first_key(&ee, name)) printf("%s   ", ee.key);
  26.     while (next_key(&ee, name) == IX_OK) printf("%s   ",ee.key);
  27.     printf("\nPress any key to continue \n");
  28.     getch();
  29.   }
  30.  
  31. void downlist(name)           /* list keys in decending order  */
  32.   IX_DESC *name;
  33.   {
  34.     ENTRY ee;
  35.     if (last_key(&ee, name)) printf("%s   ", ee.key);
  36.     while (prev_key(&ee, name) == IX_OK) printf("%s   ",ee.key);
  37.     printf("\nPress any key to continue \n");
  38.     getch();
  39.   }
  40.  
  41. void main()
  42.   {
  43.     int i;
  44.     clock_t clock(void);
  45.     float stime, etime;
  46.     ENTRY e;
  47.     printf("Make two index files\n");
  48.     make_index("test1.idx",&name1, 0);
  49.     make_index("test2.idx",&name2, 1);
  50.     printf("Indexing 100 items in two index files:\n");
  51.  
  52.     /* note the time to index */
  53.     stime = (float) clock();
  54.     /* add 100 keys to each index file */
  55.     for (i = 0; i < 100; i++)
  56.       {
  57.     e.recptr = (long) i;
  58.         sprintf(e.key, "VALUE1-%2d",i);
  59.         add_key(&e, &name1);
  60.         sprintf(e.key, "VALUE2-%2d",i);
  61.         add_key(&e, &name2);
  62.       }
  63.  
  64.     /* print the time required for indexing the two files */
  65.     etime = (float) clock();
  66.     printf("Indexing is complete.  The time was %f\n\n", (etime - stime)/CLK_TCK);
  67.     printf("List the keys in each index file in ascending order:\n\n");
  68.     uplist(&name1);
  69.     uplist(&name2);
  70.  
  71.     /* delete some keys and list again */
  72.     printf("\nNow delete all keys from 20 to 90 in each file\n\n");
  73.     for (i = 20; i < 90; i++)
  74.       {
  75.     e.recptr = (long) i;
  76.         sprintf(e.key, "VALUE1-%2d",i);
  77.         delete_key(&e, &name1);
  78.         sprintf(e.key, "VALUE2-%2d",i);
  79.         delete_key(&e, &name2);
  80.       }
  81.     printf("List the keys now for each index file in ascending order:\n\n");
  82.     uplist(&name1);
  83.     uplist(&name2);
  84.  
  85.     /* add the keys back and list again */
  86.     printf("Now add back all items from 20 to 90 to each index\n\n");
  87.     for (i = 20; i < 90; i++)
  88.       {
  89.     e.recptr = (long) i;
  90.         sprintf(e.key, "VALUE1-%d",i);
  91.         add_key(&e, &name1);
  92.         sprintf(e.key, "VALUE2-%d",i);
  93.         add_key(&e, &name2);
  94.       }
  95.     printf("List the keys for each index file again in ascending order:\n\n");
  96.     uplist(&name1);
  97.     uplist(&name2);
  98.  
  99.     /* list both files in decending order */
  100.     printf("List the keys for each index file in decending order\n\n");
  101.     downlist(&name1);
  102.     downlist(&name2);
  103.  
  104.     /* always close all files */
  105.     close_index(&name1);
  106.     close_index(&name2);
  107.   }
  108.